package tarantula.instrumenter;

import java.util.LinkedList;
import java.util.List;

import junit.framework.TestCase;

import soot.Pack;
import soot.PackManager;
import soot.Scene;
import soot.SootClass;
import soot.Transform;
import tarantula.util.Globals;

public class TestMain extends TestCase {
	
	public void testInstrumentSubject() {
		String[] args = new String[] {
				"C:/Users/Shengqi/Desktop/sai/tarantula/apachecollections/collections-3.2.1",
				"C:/Users/Shengqi/Desktop/sai/tarantula/apachecollections/collections-3.2.1-instrumented"
		};
		main(args);
	}

	/**
	 * A sample usage of using EveryStatementInstrumenter
	 * @param args
	 */
	public static void main(String[] args) {
		if(args.length != 2) {
			System.out.println("Please provide two arguments " + Globals.lineSep);
			System.out.println("  - input_dir, like: G:/72_Simplify/workspace_simplify/TarantulaJ/bin_for_test/");
			System.out.println("  - output_dir, like: G:/72_Simplify/workspace_simplify/TarantulaJ/tmp/");
			return;
		}
		/* add a phase to transformer pack by call Pack.add */
		Pack jtp = PackManager.v().getPack("jtp");
		jtp.add(new Transform("jtp.instrumenter", new EveryStatementIntrumenter()));
		
		String input_dir = args[0];
		String output_dir = args[1];
		
		/* Give control to Soot to process all options,
		 * InvokeStaticInstrumenter.internalTransform will get called. */
		List<String> sootArgs = new LinkedList<String>();
		
		sootArgs.add("-prepend-classpath");
		sootArgs.add("-keep-line-number");
		sootArgs.add("-soot-class-path");
		sootArgs.add("." + Globals.pathSep + input_dir + Globals.pathSep + Globals.getClassPath());
		
		System.out.println("." + Globals.pathSep + input_dir + Globals.pathSep + Globals.getClassPath());
//		sootArgs.add("-output-format");
//		sootArgs.add("J");
		sootArgs.add("-process-dir");
		sootArgs.add(input_dir);
		sootArgs.add("-output-dir");
		sootArgs.add(output_dir);
		
		Scene.v().addBasicClass("tarantula.instrumenter.Tracer", SootClass.SIGNATURES);
		soot.Main.main(sootArgs.toArray(new String[0]));
	}	
}
